package cn.mldn.mldncloud.service.fallback;

import cn.mldn.mldncloud.dto.RidersDTO;
import cn.mldn.mldncloud.service.IRidersService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by {wang jian} on 2018/07/17.
 */
@Component
public class RidersServiceFallbackFactory implements FallbackFactory<IRidersService> {
    @Override
    public IRidersService create(Throwable cause) {
        return new IRidersService() {

            @Override
            public RidersDTO get(long riderId) {
                RidersDTO dto = new RidersDTO();
                dto.setRiderId(1L);
                return dto;
            }

            @Override
            public List<RidersDTO> list() {
                List<RidersDTO> list = new ArrayList<>();
                RidersDTO dto = new RidersDTO();
                dto.setRname("测试数据");
                dto.setTeam("fallback是否正常");
                System.err.println("进行了fallback调用");
                list.add(dto);
                return list;
            }
        };
    }
}
